/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "VoronoiDiagramDialog.h"
#include "VoronoiDiagramGenerator.h"

namespace PQBuilder
{
	VoronoiDiagramDialog::VoronoiDiagramDialog(QWidget* parent)
		: QDialog(parent),_ui(new Ui::VoronoiDiagramDialogUI),_graphicsScene(new QGraphicsScene())
	{
		_ui->setupUi(this);
		_ui->graphicsView->setScene(_graphicsScene);
		
		connect(_ui->generateButton, SIGNAL(clicked()), this, SLOT(generate()));
		this->setModal(true);

	}

	void VoronoiDiagramDialog::generate()
	{
		float xValues[4] = {-22, -17, 4,22}; 
		float yValues[4] = {-9, 31,13,-5};

		
		long count = 4;
		PQEngine::VoronoiDiagramGenerator vdg; 
		vdg.generateVoronoi(xValues,yValues,count, -100,100,-100,100,3); 
		vdg.resetIterator(); 
		float x1,y1,x2,y2; 
		while(vdg.getNext(x1,y1,x2,y2)) {
			QLine line(QPoint(x1,y1),QPoint(x2,y2));
			_graphicsScene->addLine(line);
		}

	}

}
